const router = require('koa-router')() // 一边导入一边实例化
// const result = require('../../config/result.js')
// const { regcheck, checking } = require('../../config/checking.js')
// 操作数据库的接口
const { getToken, Updateurl } = require('../../config/databaseapi.js')
// 注册接口
router.post('/rename', async (ctx) => {
  console.log("调用文件夹/文件重命名接口")
  let { _id, fileName, currentListId, arr } = ctx.request.body;
  // console.log(_id, fileName, currentListId);
  let query = null;
  if(currentListId===0){
	  query = `db.collection("study_materials").doc("${_id}").update({data:{"fileName":"${fileName}"}})`;
  }else{
	  query = `db.collection("study_materials").doc("${currentListId}").update({data:{"include":${JSON.stringify(arr)}}})`;
	  // console.log(arr);
  }
  let res = await new getToken().posteve(Updateurl, query)
  // console.log('修改结果', res)
  if (res.errcode === 0) {
    ctx.body = { msg: "修改成功", status: 1 }
  } else {
    ctx.body = { msg: "修改失败", status: 0 }
  }
})

module.exports = router.routes()